import { readFileSync } from 'fs';
import * as path from 'path';
import { xresloaderDatablocks } from 'protos/universal/pb_header_v3';

export default class ConfigLoader {

    static load<T>(decoder: IDecoder, configName: string): Array<T> {
        var absPath = path.resolve(__dirname, `../../configs/${configName}.bin`)
        const data = xresloaderDatablocks.decode(readFileSync(absPath))
        const dataBlocks = data.dataBlock;
        const datas: Array<T> = [];
        for (let index = 0; index < dataBlocks.length; index++) {
            const dataBlock = dataBlocks[index];
            var config = decoder.decode(dataBlock);
            datas.push(config);
        }
        return datas;
    }

}
interface IDecoder {
    decode(input: any): any;
}

